package com.gwsdk.paysdk.acitvityV2.dialog;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.gwsdk.paysdk.utils.GWInflaterUtils;

public class GWGroupRuleDialog extends DialogFragment {

    private Context context;
    private String text;
    private TextView textView;
    public GWGroupRuleDialog() {

    }

    @SuppressLint("ValidFragment")
    public GWGroupRuleDialog(Context context, String text){
        this.context = context;
        this.text = text;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(GWInflaterUtils.getLayout(context,"gw_dialog_group_rule"), container, false);
        textView = view.findViewById(GWInflaterUtils.getControl(context,"content"));
        if (!TextUtils.isEmpty(text)){
            textView.setText(text);
        }
        view.findViewById(GWInflaterUtils.getControl(context,"close")).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // 设置对话框的样式
        setStyle(STYLE_NO_FRAME, GWInflaterUtils.getIdByName(context,"style","gw_preview_dialog"));
        setCancelable(false);
    }

    public void show(FragmentManager fm){
        if (fm == null) {
            return;
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(this, "GWGroupRuleDialog");
        ft.show(this);
        ft.commitAllowingStateLoss();
    }



}
